import React, {
    useState,
    useMemo,
    useEffect
} from "react";
import { getData, delData } from '../../../../common/js/fetch'
import $ from "jquery";
import "./index.scss";
import Scrollbars from "react-custom-scrollbars";
import { message, Spin } from "antd";

const _sysId = 220;

/**
 * type: user(用户), grade(年级), class(班级), group(教师/教研组), identity(管理员身份), org(部门)
 * groupType: admin(管理员), tea(教师), stu(学生), parent(家长), org(部门)
 * 
 */
function GroupList(props) {
    let {
        groupData,
        selectList,
        selectMethod,
        setGroupVisible,
        onlySelectUser
    } = props;

    const [childList, setChildList] = useState([]);
    const [oldChildList, setOldChildList] = useState([]);
    const [updateChildList, setUpdateChildList] = useState([]);
    const [getAll, setGetAll] = useState(false);
    const [childVisible, setChildVisible] = useState(false);
    const [loadVisible, setLoadVisible] = useState(false);
    const [schoolType, setSchoolType] = useState(JSON.parse(sessionStorage.getItem("schoolSystemInfo")).schoolType);
    const [schoolId, setSchoolId] = useState(JSON.parse(sessionStorage.getItem("schoolSystemInfo")).schoolId);

    const selectIdList = useMemo(() => {
        let list = [];
        //不仅仅要id相同，还得分类相同，比如学生和家长都存在年级、班级选项
        Array.isArray(selectList) &&
            selectList.forEach((item) => {
                list.push((item.groupType ? item.groupType + "_" : "") + item.id);
            })
        return list;
    }, [selectList]);
    const [showChild, setShowChild] = useState(false);
    const [historyList, setHistoryList] = useState([
        {
            id: "",
            name: groupData.name
        }
    ]);
    const [allChildList, setAllChildList] = useState([]);
    const [selectAll, setSelectAll] = useState(0);
    //获取子列表
    const getChildList = (data, type, e) => {
        console.log('daat', data);

        //根据type判断点击的是哪一层，然后调用相应的接口
        //并且将当前点击的分组放入历史点击数组中
        if (!data.type || data.type === "user") {
            return;
        }
        e && e.preventDefault();
        e && e.stopPropagation();
        let history = JSON.parse(JSON.stringify(historyList));
        let allChild = JSON.parse(JSON.stringify(allChildList));
        let dataId = (data.groupType ? data.groupType + "_" : "") + data.id
        setLoadVisible(true);
        if (data.type === "grade") {  //如果是年级，获取年级下所有班级
            let url = "api/commons/school/class/list";
            getData(url, {
                schoolType: schoolType,
                schoolId: schoolId,
                sysId: _sysId,
                gradeId: data.id,
                majorId: data.majorId
            })
                .then(res => res.json())
                .then((result) => {
                    if (result.code === "200" && Array.isArray(result.data)) {
                        let updateList = result.data.map((item) => {
                            return {
                                ...item,
                                id: item.classId,
                                collegeId: data.collegeId,
                                majorId: data.majorId,
                                groupType: data.groupType,
                                type: "class",
                                floorNum: data.floorNum + 1,
                                // parentId: dataId,
                                name: item.className
                            }
                        })
                        setChildList(updateList);
                        setLoadVisible(false);
                    }
                });
        }
        if (data.type === "class" || data.type === "stuClass" || data.type === "parentClass") {  //如果是班级则获取学生/家长
            let url = "";
            if (groupData.id === "stu" || groupData.id === "myClass") {
                url = "api/commons/school/user/students";
            } else {
                url = "api/commons/school/user/parents";
            }
            getData(url, {
                schoolType: schoolType,
                classId: data.id,
                classType: data.classType ? data.classType : "1"
            })
                .then(res => res.json())
                .then((result) => {
                    if (result.code === "200" && Array.isArray(result.data)) {
                        let updateList = result.data.map((item) => {
                            return {
                                ...item,
                                id: item.userId,
                                name: item.userName,
                                // parentId: dataId,
                                floorNum: data.floorNum + 1,
                                groupType: data.groupType,
                                type: "user"
                            }
                        })
                        setChildList(updateList);
                        setLoadVisible(false);
                    }
                });
        }
        if (data.type === "group") {  //如果是教研组获取教师列表
            let url = "api/commons/school/user/teachers";
            getData(url, {
                schoolType: schoolType,
                groupId: data.id
            })
                .then(res => res.json())
                .then((result) => {
                    if (result.code === "200" && Array.isArray(result.data)) {
                        let updateList = result.data.map((item) => {
                            return {
                                ...item,
                                id: item.userId,
                                name: item.userName,
                                // parentId: dataId,
                                floorNum: data.floorNum + 1,
                                groupType: data.groupType,
                                type: "user"
                            }
                        })
                        setChildList(updateList);
                        setLoadVisible(false);
                    }
                });
        }
        if (data.type === "college") {  //如果是学院获取专业列表
            let url = "";
            if (groupData.id === "tea") {
                url = "api/commons/school/group/list";
            } else {
                url = "api/commons/school/major/list";
            }

            getData(url, {
                collegeId: data.id,
                schoolType: schoolType,
                schoolId: schoolId
            })
                .then(res => res.json())
                .then((result) => {
                    if (result.code === "200" && Array.isArray(result.data)) {
                        let updateList = result.data.map((item) => {
                            if (groupData.id === "tea") {
                                return {
                                    ...item,
                                    id: item.groupId,
                                    name: item.groupName,
                                    collegeId: data.id,
                                    floorNum: data.floorNum + 1,
                                    // parentId: dataId,
                                    groupType: data.groupType,
                                    type: "group"
                                }
                            } else {
                                return {
                                    ...item,
                                    id: item.majorId,
                                    name: item.majorName,
                                    collegeId: data.id,
                                    floorNum: data.floorNum + 1,
                                    // parentId: dataId,
                                    groupType: data.groupType,
                                    type: "major"
                                }
                            }

                        })
                        setChildList(updateList);
                        setLoadVisible(false);
                    }
                });
        }
        if (data.type === "major") {  //如果是专业获取年级列表
            console.log(data);
            let url = "api/commons/school/grade/list";
            getData(url, {
                schoolType: schoolType,
                schoolId: schoolId,
                majorId: data.id
            })
                .then(res => res.json())
                .then((result) => {
                    if (result.code === "200" && Array.isArray(result.data)) {
                        let updateList = result.data.map((item) => {
                            return {
                                ...item,
                                id: item.gradeId,
                                name: data.majorName + item.gradeName,
                                majorId: data.id,
                                collegeId: data.collegeId,
                                floorNum: data.floorNum + 1,
                                // parentId: dataId,
                                groupType: data.groupType,
                                type: "grade"
                            }
                        })
                        setChildList(updateList);
                        setLoadVisible(false);
                    }
                });
        }
        if (data.type === "identity") {
            let url = "api/commons/school/user/identity";
            getData(url, {
                schoolId: schoolId,
                identityCode: data.id
            })
                .then(res => res.json())
                .then((result) => {
                    if (result.code === "200" && Array.isArray(result.data)) {
                        let updateList = result.data.map((item) => {
                            return {
                                ...item,
                                id: item.userId,
                                name: item.userName,
                                floorNum: data.floorNum + 1,
                                // parentId: dataId,
                                groupType: data.groupType,
                                type: "user"
                            }
                        })
                        setChildList(updateList);
                        setLoadVisible(false);
                    }
                });
        }
        if (data.type === "org") {
            if (data.childCount !== "0") {  //如果有子部门，则显示子部门
                let url = "api/commons/school/department/list";
                getData(url, {
                    sysId: "410",
                    schoolId: schoolId,
                    departmentId: data.id
                })
                    .then(res => res.json())
                    .then((result) => {
                        if (result.code === "200" && Array.isArray(result.data)) {
                            let updateList = result.data.map((item) => {
                                return {
                                    ...item,
                                    id: item.departmentId,
                                    name: item.departmentName,
                                    parentId: dataId,
                                    floorNum: data.floorNum + 1,
                                    groupType: data.groupType,
                                    type: "org"
                                }
                            })
                            url = "api/commons/school/user/department/staffs";
                            getData(url, {
                                sysId: "410",
                                schoolId: schoolId,
                                departmentId: data.id
                            })
                                .then(res => res.json())
                                .then((result) => {
                                    if (result.code === "200" && Array.isArray(result.data)) {
                                        let updateList2 = result.data.map((item) => {
                                            return {
                                                ...item,
                                                id: item.userId,
                                                name: item.userName,
                                                floorNum: data.floorNum + 1,
                                                parentId: dataId,
                                                groupType: data.groupType,
                                                type: "user",
                                                // isCheck: data.check === 2 ? true : false
                                            }
                                        })
                                        let allList = updateList.concat(updateList2);
                                        setChildList(allList);
                                        setLoadVisible(false);
                                    }
                                });
                            // setChildList(updateList);
                            // setLoadVisible(false);
                        }
                    });
            } else {
                let url = "api/commons/school/user/department/staffs";
                getData(url, {
                    sysId: "410",
                    schoolId: schoolId,
                    departmentId: data.id
                })
                    .then(res => res.json())
                    .then((result) => {
                        if (result.code === "200" && Array.isArray(result.data)) {
                            let updateList = result.data.map((item) => {
                                return {
                                    ...item,
                                    id: item.userId,
                                    parentId: dataId,
                                    floorNum: data.floorNum + 1,
                                    groupType: data.groupType,
                                    name: item.userName,
                                    type: "user",
                                    // isCheck: data.check === 2 ? true : false
                                }
                            })
                            setChildList(updateList);
                            setLoadVisible(false);
                        }
                    });
            }


        }
        if (type !== "historyClick") {
            history.push(data);
            setHistoryList(history);
        }
    }
    const clearMethod = (data, type, callback) => {
        // let updateArr = arr.map((item)=>{
        //     return (item.groupType? item.groupType + "_": "") + item.id
        // })
        // let deleteList = [data];
        // selectList.forEach((item)=>{
        //     let itemId = (item.groupType? item.groupType + "_": "") + item.id;
        //     if(updateArr.includes(itemId)){
        //         deleteList.push(item);
        //     }
        // })
        //凡是属于同一类的，并且层数大于所选分组，全部清掉
        let deleteList = type ? [] : [data];
        let id = data.id;
        let sign = false;
        selectList.forEach((item) => {
            if (item.groupType !== data.groupType) {
                return;
            }
            if (item.id === id) {
                sign = true;
                return;
            }
            let gradeId = item.gradeId;
            let classId = item.classId;
            let subjectIds = item.subjectIds;
            let identityCode = item.identityCode;
            let departId = item.departmentId;
            let fullId = item.fullPathId;
            let parentId = item.parentId && item.parentId.replace("org_", "");
            let collegeId = item.collegeId;
            let majorId = item.majorId;
            let groupId = item.groupId;
            if ((identityCode === id ||
                departId === id ||
                classId === id ||
                gradeId === id ||
                parentId === id ||
                collegeId === id ||
                majorId === id ||
                groupId === id ||
                (subjectIds && subjectIds.indexOf(id) !== -1) ||
                (item.departmentId && fullId && fullId.indexOf(id) !== -1) &&
                item.floorNum > data.floorNum)) {
                deleteList.push(item);
            }
        })
        if (!sign && type) {
            deleteList.push(data);
        }
        if (typeof callback === "function") {
            callback(deleteList);
        } else {
            selectMethod(deleteList, "", "list");
        }


    }
    const controlSelect = (value, e) => {
        e && e.stopPropagation();
        e && e.preventDefault();
        let data = historyList[historyList.length - 1];
        if (selectIdList.includes((data.groupType ? data.groupType + "_" : "") + data.id)) {
            //说明是因为父组被选才被选择
            let arr = [];
            arr.push(data);
            let valueId = (value.groupType ? value.groupType + "_" : "") + value.id;
            childList.forEach((item) => {
                let itemId = (item.groupType ? item.groupType + "_" : "") + item.id;
                if (itemId !== valueId) {
                    arr.push(item);
                }
            })
            selectMethod(arr, e, "list");
        } else {
            //需要判断其父类是否已被选择，如果父类被选中，则会被勾选，无法取消
            let sign = false;
            let valueId = value.id;
            let gradeId = value.gradeId;
            let classId = value.classId;
            let subjectIds = value.subjectIds;
            let identityCode = value.identityCode;
            let departId = value.departmentId;
            let fullId = value.fullPathId;
            let parentId = value.parentId && value.parentId.replace("org_", "");
            let collegeId = value.collegeId;
            let majorId = value.majorId;
            let groupId = value.groupId;
            selectList.forEach((item) => {
                if (item.groupType !== value.groupType) {
                    return;
                }
                if (item.id === valueId) {
                    return;
                }
                let id = item.id;
                if (item.type !== "user" && (identityCode === id ||
                    departId === id ||
                    classId === id ||
                    gradeId === id ||
                    parentId === id ||
                    collegeId === id ||
                    majorId === id ||
                    groupId === id ||
                    (subjectIds && subjectIds.indexOf(id) !== -1) ||
                    (item.departmentId && fullId && fullId.indexOf(id) !== -1))) {
                    sign = true;
                }
            })
            if (sign) {
                message.warn(`当前${value.type === "user" ? "用户" : "分组"}包含在其他选择分组中，无法取消勾选`);
                return;
            }
            //选择的时候清除所有直接子选项
            if (value.type === "user") {
                selectMethod(value, e);
            } else {
                // clearChildList(value);
                clearMethod(value);
            }
        }

    }
    //选择当前所有
    const selectGroup = (e) => {
        e.stopPropagation();
        let className = $(e.target).attr("class");
        let arr = []
        if (className === "checkedlogo") {//取消，如果存在父类则提示
            let sign = false;
            updateChildList.forEach((item) => {
                clearMethod(item, false, function (list) {
                    selectList.forEach((child) => {
                        if (child.groupType === item.groupType && child.floorNum < item.floorNum) {
                            sign = true;
                        }
                    })
                    if (!sign) {
                        arr = arr.concat(list);
                    }
                });
            })
            if (sign) {
                message.warn("当前分组包含在其他选择分组中，无法取消勾选");
                return;
            }

        } else {
            updateChildList.forEach((item) => {
                clearMethod(item, true, function (list) {
                    arr = arr.concat(list);
                });
            })
        }
        selectMethod(arr, e, "list", "delete");
    }
    const historyBack = () => {
        //删除点击的历史记录之后的记录
        let history = JSON.parse(JSON.stringify(historyList));
        history.splice(history.length - 1);
        let groupOne = history[history.length - 1];
        setHistoryList(history);
        if (!groupOne) {  //返回最外层
            setGroupVisible(false);
            return;
        }
        if (!groupOne.id) {
            setGetAll(!getAll);
            return;
        }
        getChildList(groupOne, "historyClick");
    }
    useEffect(() => {   //获取最外层目录数据
        if (!childVisible) {
            // return;
        } else {
            setLoadVisible(true);
        }
        let id = groupData.id;
        let exact = groupData.exact;
        let list = JSON.parse(JSON.stringify(allChildList));
        if (exact === "myClass" || exact === "myParent") {
            let url = "api/commons/school/class/mine";
            getData(url, {
                schoolType: schoolType,
                userId: sessionStorage.getItem("userId")
            })
                .then(res => res.json())
                .then((result) => {
                    if (result.code === "200" && Array.isArray(result.data)) {
                        let updateList = result.data.map((item) => {
                            return {
                                ...item,
                                id: item.classId,
                                type: exact === "myClass" ? "stuClass" : "parentClass",
                                groupType: exact === "myClass" ? "stu" : "parent",
                                floorNum: groupData.floorNum + 1,
                                name: item.className
                            }
                        })
                        list.push({
                            type: "my_class",
                            list: updateList
                        })
                        setChildList(updateList);
                        setLoadVisible(false);
                    }
                })
        }
        if (exact === "myGroup") {
            let url = "api/commons/school/group/mine";
            getData(url, {
                schoolId: schoolId,
                schoolType: schoolType,
                userId: sessionStorage.getItem("userId")
            })
                .then(res => res.json())
                .then((result) => {
                    if (result.code === "200" && Array.isArray(result.data)) {
                        let updateList = result.data.map((item) => {
                            return {
                                ...item,
                                id: item.subjectId || item.groupId,
                                type: "group",
                                groupType: "tea",
                                floorNum: groupData.floorNum + 1,
                                name: (item.subjectName || item.groupName) +
                                    (
                                        schoolType === "1" ?
                                            "教研组" :
                                            "教师组"
                                    )
                            }
                        })
                        list.push({
                            type: "my_group",
                            list: updateList
                        })
                        setChildList(updateList);
                        setLoadVisible(false);
                    }
                })
        }
        if (schoolType === "1") {
            if (id === "admin") {
                let url = "api/commons/school/identity/list";
                getData(url, {
                    schoolId: schoolId,
                    userType: 0
                })
                    .then(res => res.json())
                    .then((result) => {
                        if (result.code === "200" && Array.isArray(result.data)) {
                            let updateList = result.data.map((item) => {
                                return {
                                    totalCount: item.totalCount,
                                    count: item.count || item.userCount,
                                    id: item.identityCode,
                                    type: "identity",
                                    groupType: id,
                                    floorNum: groupData.floorNum + 1,
                                    name: item.identityName
                                }
                            })
                            list.push({
                                type: "all_identity",
                                list: updateList
                            })
                            setChildList(updateList);
                            setLoadVisible(false);
                        }
                    })
            }
            if (id === "tea") {
                let url = "api/commons/school/college/list";
                getData(url, {
                    schoolId: schoolId,
                    identityType: 1
                })
                    .then(res => res.json())
                    .then((result) => {
                        if (result.code === "200" && Array.isArray(result.data)) {
                            let updateList = result.data.map((item) => {
                                return {
                                    totalCount: item.totalCount,
                                    count: item.count,
                                    id: item.collegeId,
                                    type: "college",
                                    groupType: id,
                                    floorNum: groupData.floorNum + 1,
                                    name: item.collegeName
                                }
                            })
                            list.push({
                                type: "college",
                                list: updateList
                            })
                            setChildList(updateList);
                            setLoadVisible(false);
                        }
                    })
            }
            if (id === "stu" || id === "parent") {
                let url = "api/commons/school/college/list";
                getData(url, {
                    schoolId: schoolId,
                    identityType: 2
                })
                    .then(res => res.json())
                    .then((result) => {
                        if (result.code === "200" && Array.isArray(result.data)) {
                            let updateList = result.data.map((item) => {
                                return {
                                    totalCount: item.totalCount,
                                    count: item.count,
                                    id: item.collegeId,
                                    type: "college",
                                    groupType: id,
                                    floorNum: groupData.floorNum + 1,
                                    name: item.collegeName
                                }
                            })
                            list.push({
                                type: "college",
                                list: updateList
                            })
                            setChildList(updateList);
                            setLoadVisible(false);
                        }
                    })
            }
            if (id === "org") {
                let url = "api/commons/school/department/list";
                getData(url, {
                    sysId: "410",
                    departmentId: "",
                    schoolId: schoolId
                })
                    .then(res => res.json())
                    .then((result) => {
                        if (result.code === "200" && Array.isArray(result.data)) {
                            let updateList = result.data.map((item) => {
                                return {
                                    ...item,
                                    id: item.departmentId,
                                    type: "org",
                                    groupType: id,
                                    floorNum: groupData.floorNum + 1,
                                    name: item.departmentName
                                }
                            })
                            list.push({
                                type: "all_org",
                                list: updateList
                            })
                            setChildList(updateList);
                            setLoadVisible(false);
                        }
                    })
            }
            return;
        }
        if (id === "admin") {
            let url = "api/commons/school/identity/list";
            getData(url, {
                schoolId: schoolId,
                userType: 0
            })
                .then(res => res.json())
                .then((result) => {
                    if (result.code === "200" && Array.isArray(result.data)) {
                        let updateList = result.data.map((item) => {
                            return {
                                totalCount: item.totalCount,
                                count: item.count || item.userCount,
                                id: item.identityCode,
                                type: "identity",
                                groupType: id,
                                floorNum: groupData.floorNum + 1,
                                name: item.identityName
                            }
                        })
                        list.push({
                            type: "all_identity",
                            list: updateList
                        })
                        setChildList(updateList);
                        setLoadVisible(false);
                    }
                })
        }
        if (id === "tea" && !exact) {
            let url = "api/commons/school/group/list";
            getData(url, {
                schoolType: schoolType,
                schoolId: schoolId,
                collegeId: ""
            })
                .then(res => res.json())
                .then((result) => {
                    if (result.code === "200" && Array.isArray(result.data)) {
                        let updateList = result.data.map((item) => {
                            return {
                                totalCount: item.totalCount,
                                count: item.count || item.classCount,
                                id: item.subjectId || item.collegeId,
                                type: "group",
                                groupType: id,
                                floorNum: groupData.floorNum + 1,
                                name: (item.subjectName || item.groupName) + (schoolType == 2 ? "教师组" : "教研组")
                            }
                        })
                        list.push({
                            type: "all_tea",
                            list: updateList
                        })
                        setChildList(updateList);
                        setLoadVisible(false);
                    }
                })
        }
        if ((id === "stu" || id === "parent") && !exact) {
            let url = "api/commons/school/grade/list";
            getData(url, {
                schoolType: schoolType,
                schoolId: schoolId,
                sysId: _sysId
            })
                .then(res => res.json())
                .then((result) => {
                    if (result.code === "200" && Array.isArray(result.data)) {
                        let updateList = result.data.map((item) => {
                            return {
                                totalCount: item.totalCount,
                                count: item.count || item.classCount,
                                id: item.gradeId,
                                type: "grade",
                                groupType: id,
                                floorNum: groupData.floorNum + 1,
                                name: item.gradeName
                            }
                        })
                        list.push({
                            type: "all_grade",
                            list: updateList
                        })
                        setChildList(updateList);
                        setLoadVisible(false);
                    }
                })
        }
        if (id === "org") {
            let url = "api/commons/school/department/list";
            getData(url, {
                sysId: "410",
                departmentId: "",
                schoolId: schoolId
            })
                .then(res => res.json())
                .then((result) => {
                    if (result.code === "200" && Array.isArray(result.data)) {
                        let updateList = result.data.map((item) => {
                            return {
                                ...item,
                                id: item.departmentId,
                                type: "org",
                                groupType: id,
                                floorNum: groupData.floorNum + 1,
                                name: item.departmentName
                            }
                        })
                        list.push({
                            type: "all_org",
                            list: updateList
                        })
                        setChildList(updateList);
                        setLoadVisible(false);
                    }
                })
        }
    }, [childVisible, getAll]);

    useEffect(() => {  //用于判断当前列表各个选择状态

        let list = JSON.parse(JSON.stringify(childList));
        console.log(list, 'childList', selectList);
        let groupCount = 0;
        let helfCount = false;
        list.forEach((item) => {
            if (item.floorNum === 3) {
                setOldChildList(list);
            }
            let sign = [];  // 0未选，1半选，2全选
            let count = 0;
            let id = item.id;
            let itemGradeId = item.gradeId;
            let itemClassId = item.classId;
            let itemSubjectIds = item.subjectIds;
            let itemIdentityCode = item.identityCode;
            let itemDepartId = item.departmentId;
            let itemFullId = item.fullPathId;
            let itemCollegeId = item.collegeId;
            let itemMajorId = item.majorId;
            let itemGroupId = item.groupId;
            let itemParentId = item.parentId && item.parentId.replace("org_", "");
            selectList.forEach((child) => {
                let chilId = child.id;
                let gradeId = child.gradeId;
                let classId = child.classId;
                let subjectIds = child.subjectIds;
                let identityCode = child.identityCode;
                let departId = child.departmentId;
                let fullId = child.fullPathId;
                let parentId = child.parentId && child.parentId.replace("org_", "");
                let collegeId = child.collegeId;
                let majorId = child.majorId;
                let groupId = child.groupId;
                if (child.groupType !== item.groupType) {
                    //搜索出来的用户没有groupType，所以需要放开限制额外判断
                    if (child.type === "user" && id === chilId) {
                        sign.push(2);
                    }
                    return;
                }
                if (item.type === "user" && child.type === "user" && !child.parentId) {  //如果是用户，则判断userId就行，组织结构除外
                    if (id === chilId) {
                        sign.push(2);
                    }
                    return;
                }
                if (chilId === itemDepartId ||
                    chilId === itemIdentityCode ||
                    chilId === itemClassId ||
                    chilId === itemGradeId ||
                    chilId === itemParentId ||
                    chilId === itemCollegeId ||
                    chilId === itemMajorId ||
                    chilId === itemGroupId ||
                    // item.isCheck === true ||
                    (itemSubjectIds && itemSubjectIds.indexOf(chilId) !== -1) ||
                    (item.departmentId && child.departmentId && itemFullId && itemFullId.indexOf(chilId) !== -1)) {
                    if (majorId && majorId !== itemMajorId) {
                        return;
                    }
                    sign.push(2);
                }
                if (identityCode === id ||
                    departId === id ||
                    classId === id ||
                    gradeId === id ||
                    parentId === id ||
                    collegeId === id ||
                    majorId === id ||
                    groupId === id ||
                    (subjectIds && subjectIds.indexOf(id) !== -1) ||
                    (item.departmentId && fullId && fullId.indexOf(id) !== -1)) {
                    sign.push(1);
                    if (child.floorNum === item.floorNum + 1) {
                        count++;
                    }

                }
                if (chilId === id) {
                    if (majorId && majorId !== itemMajorId) {
                        return;
                    }
                    if (identityCode && identityCode !== itemIdentityCode) {
                        return;
                    }
                    sign.push(2);
                }
            })

            //2023修复学校组织架构全选不选择教师
            let oldList = JSON.parse(JSON.stringify(oldChildList));
            oldList.forEach(itm => {
                let itmId = itm.id;
                let departmentId = itm.departmentId;
                if (!departmentId || !itmId) return;
                if ((itemParentId.indexOf(itmId) > -1 || itemParentId.indexOf(departmentId) > -1) && itm.check === 2) {
                    sign.push(2);
                }
            })

            if (count && (count == item.count || count == item.childCount)) {
                sign.push(2);
            }
            item.check = Math.max(...sign);
            if (item.check === 2) {
                groupCount++;
            } else if (item.check === 1) {
                helfCount = true;
            }
        })
        if (groupCount && groupCount === list.length) {
            setSelectAll(2);
        } else if (groupCount || helfCount) {
            setSelectAll(1);
        } else {
            setSelectAll(0);
        }
        console.log('list11', list);

        setUpdateChildList(list);
    }, [selectList, childList]);
    return (
        <div className="group_one">
            <Spin
                opacity={false}
                // wrapperClassName={`collect_load ${childVisible? "": "none"}`} 
                spinning={loadVisible} tip="数据加载中...">
                <ul className="child_list">
                    <div className="step_list">
                        <p className="step_title">
                            <i className="leftlogo" onClick={historyBack}></i>
                            选择{groupData.name}
                        </p>
                        <p className="step_container" title={
                            historyList.map((item) => {
                                return item.name
                            }).join("/")
                        }>
                            {
                                historyList.map((item, index) => {
                                    return (
                                        <span className="step_one" key={index}>
                                            {
                                                index ?
                                                    "" :
                                                    "选择"
                                            }
                                            {item.name}
                                            {
                                                index === historyList.length - 1 ?
                                                    "" :
                                                    "/"
                                            }
                                        </span>
                                    )
                                })
                            }
                        </p>
                    </div>
                    <Scrollbars autoHeight autoHeightMax={510}>
                        {
                            updateChildList.length > 0 && !onlySelectUser ?
                                <div className="all_container">
                                    <i className={
                                        selectAll === 1 ?
                                            "helflogo" :
                                            selectAll === 2 ?
                                                "checkedlogo" :
                                                "checklogo"
                                    } onClick={selectGroup}></i>
                                    全选
                                </div> :
                                ""
                        }
                        {
                            updateChildList.length > 0 ?
                                updateChildList.map((item, index) => {
                                    console.log('item12', item);

                                    return (
                                        <li
                                            className="child_one"
                                            key={index}
                                            // onClick={(e)=>controlSelect(item, e)}
                                            onClick={(e) => getChildList(item, "", e)}
                                            style={{
                                                cursor: (item.userId ? "default" : "")
                                            }}
                                            title={item.name}>
                                            {
                                                !onlySelectUser ?
                                                    <i className={
                                                        item.check === 2 ?
                                                            "checkedlogo" :
                                                            item.check === 1 ?
                                                                "helflogo" :
                                                                "checklogo"
                                                    } onClick={(e) => controlSelect(item, e)}></i>
                                                    : (item.type === 'user' ? <i className={
                                                        item.check === 2 ?
                                                            "checkedlogo" :
                                                            item.check === 1 ?
                                                                "helflogo" :
                                                                "checklogo"
                                                    } onClick={(e) => controlSelect(item, e)}></i> : <i style={{ width: '24px' }}></i>)
                                            }

                                            {
                                                item.avatarPath ?
                                                    <i className="user_image" style={{
                                                        backgroundImage: `url('${item.avatarPath}')`
                                                    }}></i> :
                                                    ""
                                            }
                                            {item.name}
                                            {
                                                item.userId ?
                                                    <span style={{ color: "#999", marginLeft: 3 }}>({item.userId})</span> :
                                                    <>
                                                        <span style={{ color: "#999", marginLeft: 3 }}>({item.totalCount}人)</span>
                                                        <i className="rightlogo" onClick={(e) => getChildList(item, "", e)}></i>
                                                    </>

                                                // <span className="next-floor" onClick={(e)=>getChildList(item, "", e)}><i className="leftlogo"></i>下级</span>
                                            }
                                        </li>
                                    )
                                }) :
                                <p className="group_empty">该分组暂无成员</p>
                        }
                    </Scrollbars>
                </ul>
            </Spin>
        </div>
    )
}

export default GroupList;